<?php
/**
 * easywechat 使用thinkphp缓存
 */
namespace wechat;

use EasyWeChat\MicroMerchant\Application as microMerchantApplication;
use EasyWeChat\MiniProgram\Application as miniProgramApplication;
use EasyWeChat\OfficialAccount\Application as officialAccountApplication;
use EasyWeChat\OpenPlatform\Application as openPlatformApplication;
use EasyWeChat\OpenWork\Application as openWorkApplication;
use EasyWeChat\Payment\Application as paymentApplication;
use EasyWeChat\Work\Application as workApplication;

class Factory {

    /**
     * 微信支付
     * @param array $config
     * @return paymentApplication
     */
    static public function payment($config = []) {
        $config = !empty($config) ? $config : config('wechat.payment');
        $app = \EasyWeChat\Factory::payment($config);
        $app->rebind('cache', new CacheBridge());
        return $app;
    }

    /**
     * 小程序
     * @param array $config
     * @return miniProgramApplication
     */
    static public function miniProgram($config = []) {
        $config = !empty($config) ? $config : config('wechat.mini_program');
        $app = \EasyWeChat\Factory::miniProgram($config);
        $app->rebind('cache', new CacheBridge());
        return $app;
    }

    /**
     * 微信开放平台第三方平台
     * @param array $config
     * @return openPlatformApplication
     */
    static public function openPlatform($config = []) {
        $config = !empty($config) ? $config : config('wechat.open_platform');
        $app = \EasyWeChat\Factory::openPlatform($config);
        $app->rebind('cache', new CacheBridge());
        return $app;
    }

    /**
     * 公众号
     * @param array $config
     * @return officialAccountApplication
     */
    static public function officialAccount($config = []) {
        $config = !empty($config) ? $config : config('wechat.official_account');
        $app = \EasyWeChat\Factory::officialAccount($config);
        $app->rebind('cache',new CacheBridge());
        return $app;
    }

    /**
     * 企业微信
     * @param array $config
     * @return workApplication
     */
    static public function work($config = []) {
        $config = !empty($config) ? $config : config('wechat.work');
        $app = \EasyWeChat\Factory::work($config);
        $app->rebind('cache', new CacheBridge());
        return $app;
    }

    /**
     * 企业微信第三方服务商
     * @param array $config
     * @return openWorkApplication
     */
    static public function openWork($config = []) {
        $config = !empty($config) ? $config : config('wechat.open_work');
        $app = \EasyWeChat\Factory::openWork($config);
        $app->rebind('cache', new CacheBridge());
        return $app;
    }

    /**
     * 小微商户
     * @param array $config
     * @return microMerchantApplication
     */
    static public function microMerchant($config = []) {
        $config = !empty($config) ? $config : config('wechat.micro_merchant');
        $app = \EasyWeChat\Factory::microMerchant($config);
        $app->rebind('cache', new CacheBridge());
        return $app;
    }

}